# import json
# from torch.utils.tensorboard import SummaryWriter
#
# with open('metrics.json') as json_file:
#     data = json.load(json_file)
#     # print(data)
#     writer = SummaryWriter()
#     for i in range(len(data)):
#         # print(data[0]['data_time'])
#         # print(i)
#         # print(data[i]['total_loss'])
#
#         writer.add_scalar('total_loss', data[i]['total_loss'], data[i]['iteration'])
#         writer.add_scalar('loss_bbox', data[i]['loss_bbox'], data[i]['iteration'])
#         writer.add_scalar('loss_ce', data[i]['loss_ce'], data[i]['iteration'])
#         writer.add_scalar('loss_giou', data[i]['loss_giou'], data[i]['iteration'])
# writer.close()

import json
from torch.utils.tensorboard import SummaryWriter

writer = SummaryWriter()
with open("tools/loss_tensorboard_logger/metrics/libra_r-cnn/coco/20210210_183031.log.json") as json_file:
    data = json.load(json_file)
    # print(data)
    for i in range(len(data)):
        # print(data[0]['data_time'])
        # print(i)
        # print(data[i]['total_loss'])
        writer.add_scalars('loss', {'total_loss': data[i]['total_loss'],
                                    'loss_bbox': data[i]['loss_bbox'],
                                    'loss_ce': data[i]['loss_ce'],
                                    'loss_giou': data[i]['loss_giou']}, data[i]['iteration'])
        writer.add_scalars('loss', {'total_loss': data[i]['total_loss']}, data[i]['iteration'])
print("finish")

